package com.module.home;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.module.home.action.FragmentActAction;
import com.orhanobut.logger.Logger;
import com.module.bean.beans.LoginBean;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import com.module.home.action.FragmentContract;
import com.module.home.view.PublicDialog;
import ren.nearby.http.base.BaseLazyLoadFragment;
import ren.nearby.http.base.IPresenter;
import ren.nearby.http.meepo.Meepo;
import ren.nearby.http.meepo.config.UriConfig;



/**
 * Created by Administrator on 2017/7/27 0027.
 */

public class NearbyFragmentMe extends BaseLazyLoadFragment implements FragmentContract.View{

    ActivityRouter router;

    //    @BindView(R2.id.home_tv_test_platform)
    TextView home_tv_platform;
    //    @BindView(R2.id.home_tv_home)
    TextView home_tv_home;
    //    @BindView(R2.id.home_tv_main)
    TextView home_tv_main_login;
    TextView home_tv_fragment;
    //    @BindView(R2.id.home_tv_view)
    TextView home_tv_view_web;
    TextView home_tv_main_web;
    TextView home_tv_main_code;

    //    @BindView(R2.id.home_tv_test_view)
    TextView home_tv_view_welcome;
    TextView home_tv_test_view_login;
    TextView home_tv_jni_bitmap;
    TextView home_tv_dagger2_template;
    TextView home_tv_tinker;
    //    @BindView(R2.id.home_tv_test_browsable)
    TextView home_tv_browser;


    @Override
    protected int getLayoutRes() {
        return R.layout.home_neraby_fragment_me;
    }

    @Override
    public void onFragmentFirstVisible() {
        super.onFragmentFirstVisible();
        Logger.e("显示UI 加载数据");
        if(action!=null){
            action.test();

        }else{
            Logger.e("action null ");
        }

        Logger.e(loginBean == null ?
                "value = 1" :
                " value = 0" + loginBean.getUsername() + " - " + loginBean.isIps());
    }

    public void doublePermissions() {

    }

    @Override
    public void setPresenter(FragmentActAction presenter) {

    }

    private PublicDialog.Builder dialog;



    @Inject
    FragmentContract.Action action;

    @Inject
    LoginBean loginBean;

    @Override
    protected void initView(View view) {

        home_tv_platform = view.findViewById(R.id.home_tv_platform);
        home_tv_home = view.findViewById(R.id.home_tv_home);
        home_tv_main_login = view.findViewById(R.id.home_tv_main_login);
        home_tv_fragment = view.findViewById(R.id.home_tv_fragment);
        home_tv_view_welcome = view.findViewById(R.id.home_tv_view_welcome);
        home_tv_main_code = view.findViewById(R.id.home_tv_main_code);

        home_tv_view_web = view.findViewById(R.id.home_tv_view_web);
        home_tv_main_web = view.findViewById(R.id.home_tv_main_web);
        home_tv_test_view_login = view.findViewById(R.id.home_tv_test_view_login);
        home_tv_jni_bitmap = view.findViewById(R.id.home_tv_jni_bitmap);
        home_tv_dagger2_template = view.findViewById(R.id.home_tv_dagger2_template);
        home_tv_tinker = view.findViewById(R.id.home_tv_tinker);
        home_tv_browser = view.findViewById(R.id.home_tv_browser);



        final Meepo meepo = new Meepo.Builder()
                .config(new UriConfig().scheme("action").host("nearby.action"))
                .build();
        router = meepo.create(ActivityRouter.class);

        home_tv_home.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                router.gotoHome(getActivity(), "Me界面而来");
            }
        });

        home_tv_fragment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("value1", "值1");
                map.put("value2", "值2");

//                router.gotoB(NWelcome.this, map);
                //多个参数传递与跳转Code与返回
                map.put("value3", "值3");
                router.gotoFragment(getActivity(), "Me界面而来");
            }
        });


        home_tv_main_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("value1", "值1");
                map.put("value2", "值2");

//                router.gotoB(NWelcome.this, map);
                //多个参数传递与跳转Code与返回
                map.put("value3", "值3");
                router.gotoMainLogin(getActivity(), map);
            }
        });

        home_tv_main_code.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("value1", "值1");
                map.put("value2", "值2");

//                router.gotoB(NWelcome.this, map);
                //多个参数传递与跳转Code与返回
                map.put("value3", "值3");
                router.gotoMainLogin(getActivity(), map, 103);
            }
        });


        home_tv_view_welcome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("value1", "值1");
                map.put("value2", "值2");

//                router.gotoB(NWelcome.this, map);
                //多个参数传递与跳转Code与返回
                map.put("value3", "值3");
                router.gotoViewWelcome(getActivity(), map);
            }
        });

        home_tv_view_web.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("value1", "值1");
                map.put("value2", "值2");

//                router.gotoB(NWelcome.this, map);
                //多个参数传递与跳转Code与返回
                map.put("value3", "值3");
//                router.gotoTestView(getActivity(),map);
                router.gotoViewH5Web(getActivity(), map);


            }
        });

        home_tv_main_web.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("value1", "http://b.nearby.ren/");
                map.put("value2", "值2");

//                router.gotoB(NWelcome.this, map);
                //多个参数传递与跳转Code与返回
                map.put("value3", "值3");
//                router.gotoTestView(getActivity(),map);
                router.gotoMainX5H5Web(getActivity(), map);


            }
        });
        home_tv_test_view_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("value1", "值1");
                map.put("value2", "值2");

//                router.gotoB(NWelcome.this, map);
                //多个参数传递与跳转Code与返回
                map.put("value3", "值3");
                router.gotoTestViewLogin(getActivity(), map);
            }
        });

        home_tv_jni_bitmap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("value1", "值1");
                map.put("value2", "值2");

//                router.gotoB(NWelcome.this, map);
                //多个参数传递与跳转Code与返回
                map.put("value3", "值3");
                router.gotoMainCompress(getActivity(), map);


            }
        });
        home_tv_dagger2_template.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("value1", "值1");
                map.put("value2", "值2");

//                router.gotoB(NWelcome.this, map);
                //多个参数传递与跳转Code与返回
                map.put("value3", "值3");
                router.gotoMainDagger2Template(getActivity(), map);


            }
        });
        home_tv_tinker.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("value1", "值1");
                map.put("value2", "值2");

//                router.gotoB(NWelcome.this, map);
                //多个参数传递与跳转Code与返回
                map.put("value3", "值3");
                router.gotoMainTinker(getActivity(), map);
            }
        });
        home_tv_platform.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("value1", "值1");
                map.put("value2", "值2");

//                router.gotoB(NWelcome.this, map);
                //多个参数传递与跳转Code与返回
                map.put("value3", "值3");
                router.gotoMainPlatform(getActivity(), map);
            }
        });

        home_tv_browser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri = Uri.parse("http://b.nearby.ren/naerby.html");
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                intent.setData(uri);
                startActivity(intent);


            }
        });

    }


    @Override
    protected BaseLazyLoadFragment getFragment() {
        return this;
    }

    @Override
    public IPresenter getPresenter() {
        return null;
    }



    /**
     * 测试router.gotoViewWelcome2 方法返回
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //测试Meepo请求code返回
        Logger.e(" me Home 组件 " + "requestCode = " + requestCode + " - resultCode = " + resultCode);


    }
}
